package net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

/*
 * 客户端
 */
public class TcpClient {
	
	public static void main(String[] args) {
		
		Scanner input =new Scanner(System.in);
		
		try {
			//连接服务器
			Socket socket=new Socket("localhost", 9090);
			//要输出流
			OutputStream os= socket.getOutputStream();
			String info=null;
			while(true) {
				info=input.nextLine();
				System.out.println("客户说"+info);
				if (info.equals("exit")) {
					break;
				}
				os.write(info.getBytes());
				os.flush();
			} 
			os.close();
			socket.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
//		socket.shutdownOutput();
		
		/*
		//要输入流
		InputStream is= socket.getInputStream();
		InputStreamReader isr=new InputStreamReader(is);
		BufferedReader br=new BufferedReader(isr);
		String info= br.readLine();
		System.out.println("服务器返回消息"+info);
		
		//关闭资源
		br.close();
		isr.close();
		is.close();
		*/
//		pw.close();
		
		
		
	}

}
